<template>
    <div>
        <el-dialog :visible.sync="visible" title="巡检点管理" width="30%" center @closed="dialogReset">
            <el-form ref="form" :model="form" label-width="100px">
                <el-form-item v-show="false" label="巡检路线ID" prop="routeId">
                    <el-input v-model="form.routeId"></el-input>
                </el-form-item>
                <el-form-item label="巡检点ID" prop="id">
                    <el-input v-model="form.id" disabled></el-input>
                </el-form-item>
                <el-form-item label="巡检点名称" prop="name">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="巡检点简称" prop="pointAlpha">
                    <el-input v-model="form.pointAlpha"></el-input>
                </el-form-item>
                <el-form-item label="标识类型" prop="markType">
                    <el-select v-model="form.markType" placeholder="请选择标识类型">
                        <el-option label="二维码" :value="1"></el-option>
                        <el-option label="蓝牙" :value="2"></el-option>
                        <el-option label="NFC" :value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop="isScan">
                    <el-checkbox label="巡检单是否需要扫描标签方可开启该巡更点" name="type" v-model="form.isScan"></el-checkbox>
                </el-form-item>
                <el-form-item prop="isEffective">
                    <el-tooltip content="dasdad"></el-tooltip>
                    <el-checkbox label="是否有效" name="type" v-model="form.isEffective"></el-checkbox>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="success" @click="dataFormSubmit()">确 定</el-button>
                <el-button @click="visible = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {nanoid} from 'nanoid'

    export default {
        name: "point-add",
        data() {
            return {
                form: {
                    id: null,
                    name: '',
                    pointAlpha: '',
                    markType: 1,
                    isScan: 0,
                    isEffective: 0,
                    routeId: null,
                    routes: []
                },
                visible: false
            }
        },
        methods: {
            dialogReset() {
                this.$refs['form'].resetFields();
            },
            init() {
                this.visible = true;
                this.$nextTick(() => {
                    this.$refs['form'].resetFields();
                });
            },
            dataFormSubmit() {
                // 获取表单中的所有填写好的参数值
                let params = {
                    id: nanoid(),
                    name: this.form.name,
                    pointAlpha: this.form.pointAlpha,
                    markType: this.form.markType,
                    isScan: this.form.isScan ? 1 : 0,
                    isEffective: this.form.isEffective ? 1 : 0,
                    routeId: this.form.routeId,
                };

                console.log(params);
                this.showMessage('添加巡检点成功', params);
            },
            showMessage(msg, params) {
                this.$message({
                    message: msg,
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                        this.visible = false;
                        this.$emit('refresh', params);
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>
